#include <iostream>
#include <sstream>

using namespace std;

bool isPrime(int n) {
    if (n < 2) {
        return false;
    }
    for (int i = 2; i < n; i++) {
        if (n % i == 0) {
            return false;
        }
    }
    return true;
}

int main() {
    string h;
    getline(cin, h);

    int prob = 0;
    for (int k = 0; k < h.size(); k++) {
        if (h[k] == ' ') {
            prob++;
        }
    }

    if (prob != 2) {
        cout << "Wrong input" << endl;
    } else {
        string a, b, c;
        istringstream iss(h);
        iss >> a >> b >> c;

        string m[] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};

        bool validInput = false;
        int num = 0;
        for (int i = 0; i < 10; i++) {
            if (a == m[i]) {
                num += i * 100;
                validInput = true;
                break;
            }
        }
        for (int i = 0; i < 10; i++) {
            if (b == m[i]) {
                num += i * 10;
                break;
            }
        }
        for (int i = 0; i < 10; i++) {
            if (c == m[i]) {
                num += i;
                break;
            }
        }

        if (validInput && num > 0) {
            if (isPrime(num)) {
                cout << num << endl;
            } else {
                int x = 0, y = 0;
                for (int r = num + 1; r < 1100; r++) {
                    if (isPrime(r)) {
                        x = r;
                        break;
                    }
                }

                for (int j = num - 1; j > 0; j--) {
                    if (isPrime(j)) {
                        y = j;
                        break;
                    }
                }

                if ((x - num) < (num - y)) {
                    cout << x << endl;
                } else if ((x - num) > (num - y)) {
                    cout << y << endl;
                } else if ((x - num) == (num - y)) {
                    cout << y << endl;
                }
            }
        } else {
            cout << "Wrong input" << endl;
        }
    }

    return 0;
}

